#pragma once
#include "libutilsbase.h"
#include "tchar.h"
#include <string>
#include <comutil.h>
#pragma comment(lib,"comsuppw.lib")
LIB_NS_BEGIN

class  UComHelper
{
public:
	static std::wstring ToWS(std::string str)
	{
		_bstr_t s(str.c_str());
		std::wstring ret = (wchar_t*) s;
		return ret;
	}
	static std::wstring ToWS(std::wstring str)
	{
		return str;
	}

	static tstring ToTS(std::string str)
	{
#if  defined(UNICODE) || defined(_UNICODE)
		return ToWS(str);
#else
		return ToAS(str);
#endif
	}

	static tstring ToTS(const TCHAR* str)
	{
		tstring data = str;
#if  defined(UNICODE) || defined(_UNICODE)
		return ToWS(data);
#else
		return ToAS(data);
#endif
	}

	static std::string ToAS(std::wstring str)
	{
		_bstr_t s(str.c_str());
		std::string ret = (const char*) s;
		return ret;
	}

	static std::string ToAS(std::string str)
	{
		return str;
	}

	static bool CreateGuid(GUID* pGuid)
	{
		::CoCreateGuid(pGuid);	
		return true;
	}


	bool StringtoCLSID( const TCHAR* lpsz, CLSID* lpClsID )
	{
		HRESULT hr;
		if (lpsz[0] == '{')
			hr = ::CLSIDFromString((LPOLESTR)(lpsz), lpClsID);
		else
			hr = ::CLSIDFromProgID((LPOLESTR)lpsz, lpClsID);
		return SUCCEEDED(hr) ==  TRUE ? true :false;
	}


};

LIB_NS_END